<template>


  <div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <!--添加门店-->
      <div class="common-form">新增電子面單配置</div>
      <el-form-item label="電子面單配置名稱" prop="settingName" :rules="[{required: true,message: ' '}]">
        <el-input v-model="form.settingName" class="max-w460"></el-input>
      </el-form-item>

      <el-form-item label="快遞公司">
        <el-select
            size="small"
            v-model="form.expressId"
            placeholder="請選擇"
        >
          <el-option
              v-for="(item, index) in expressList"
              :key="index"
              :label="item.expressName"
              :value="item.expressId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="電子面單月結賬號" prop="partnerId" :rules="[{required: true,message: ' '}]">
        <el-input v-model="form.partnerId"  class="max-w460"></el-input>
        <div class="tips">電子面單客戶編碼或月結賬號，使用電子面單下單時必填，需貴司向當地快遞公司網點申請，其餘字段請對照快遞100參數字典根據快遞公司類型填寫<el-link :underline="false" href="https://api.kuaidi100.com/document/5f0ff6e82977d50a94e10237.html" target="_blank"
                   type="primary">快遞100參數字典</el-link>
        </div>
        <div class="tips"></div>
      </el-form-item>
      <el-form-item label="電子面單密碼">
        <el-input v-model="form.partnerKey"  class="max-w460"></el-input>
      </el-form-item>
      <el-form-item label="電子面單密鑰">
        <el-input v-model="form.partnerSecret"  class="max-w460"></el-input>
      </el-form-item>
      <el-form-item label="電子面單客戶賬戶名稱">
        <el-input v-model="form.partnerName"  class="max-w460"></el-input>
      </el-form-item>
      <el-form-item label="收件網點名稱">
        <el-input v-model="form.net"  class="max-w460"></el-input>
      </el-form-item>
      <el-form-item label="電子面單承載編號">
        <el-input v-model="form.code"  class="max-w460"></el-input>
      </el-form-item>
      <el-form-item label="電子面單承載快遞員名">
        <el-input v-model="form.checkMan"  class="max-w460"></el-input>
      </el-form-item>

      <el-form-item label="排序">
        <el-input v-model="form.sort" type="number" class="max-w460"></el-input>
        <div class="tips">數字越小越靠前</div>
      </el-form-item>

      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit" :loading="loading">提交</el-button>
      </div>


    </el-form>


  </div>

</template>

<script>
import SettingApi from '@/api/setting.js';
export default {
  data() {
    return {
      loading: false,
      /*form表单数据*/
      form: {
        sort: 1
      },
      /*快递公司列表*/
      expressList: []
    };
  },
  created() {
    /*获取列表*/
    this.getParams();
  },
  methods: {
    getParams() {
      let self = this;
      SettingApi.toAddlabel({}, true).then(res => {
        self.loading = false;
        self.expressList = res.data.expressList;
      }).catch(error => {
        self.loading = false;
      });
    },
    //提交表单
    onSubmit() {
      let self = this;
      let form = this.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.loading = true;
          SettingApi.addlabel(form, true).then(data => {
            self.loading = false;
            ElMessage({
              message: "恭喜您，新增成功",
              type: 'success'
            });
            self.$router.push('/setting/label/index');
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    }
  }
};
</script>

<style>
.tips {
    color: #ccc;
  }
</style>

